import { URL_MY_WALLET, URL_CREATEORDER } from './../constants/SystemConstants';
import { WXRequest } from './../utils/WXRequest';
import { SET_CABINETID, GET_USERWALLET_PENDING, GET_USERWALLET_RESOLVE, GET_USERWALLET_REJECT, SET_LOCATIONDETAILVISIBLE } from './../constants/global';

export const setCabinetId = (id) => {
  return {
    type: SET_CABINETID,
    cabinetId: id
  }
}

export const getUserWallet = () => async dispatch => {
  dispatch({
    type: GET_USERWALLET_PENDING
  })
  WXRequest(URL_MY_WALLET, 'GET', {}).then(res => {
    dispatch({
      type: GET_USERWALLET_RESOLVE,
      userWallet: res.data
    })
    console.log(res)
  }).catch(e => {
    dispatch({
      type: GET_USERWALLET_REJECT
    })
    console.error(e)
  })
}

export const createOrder = (orderData) => async dispatch => {
  WXRequest(URL_CREATEORDER, 'POST', orderData).then(res => {
    console.log(res)
  }).catch(e => {
    console.error(e)
  })
}

export const setLocationVisible = (visible, type) => {
  return {
    type: SET_LOCATIONDETAILVISIBLE,
    location: {
      visible: visible,
      type: type
    }
  }
}